package com.yhy.wxzn.wms.controller;

import com.alibaba.fastjson.JSONObject;
import com.yhy.wxzn.common.utils.CryptoUtil;
import com.yhy.wxzn.wms.service.IWmsPdaService;
import com.yhy.wxzn.wms.vo.WmsASNReceiveVo;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.base.entity.JeecgEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: 97354
 * @Date: 2023/11/3 13:44
 * @Description: WmsPdaController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/pda")
@Slf4j
public class WmsPdaController extends JeecgController<JeecgEntity, IWmsPdaService> {

    @Autowired
    private IWmsPdaService wmsPdaService;

    /**
     * PDA收货列表查询
     * */
    @RequestMapping(value = "/initReceiveList", method = RequestMethod.GET)
    public Result<?> initReceiveList(@RequestParam(name = "searchParam") String searchParam) {
        if(!StringUtils.isEmpty(searchParam)){
            searchParam = CryptoUtil.desEncrypt(searchParam, CryptoUtil.KEY, CryptoUtil.IV);
        }
        List<WmsASNReceiveVo> receiveVos = wmsPdaService.findReceiveListByParam(searchParam);
        return Result.OK(receiveVos);
    }

    /**
     * PDA收货明细列表
     * */
    @RequestMapping(value = "/initReceiveDetailList", method = RequestMethod.GET)
    public Result<?> initReceiveDetailList(@RequestParam(name = "asnId") String asnId,@RequestParam(name = "searchParam") String searchParam,@RequestParam(name = "palletNo") String palletNo) {
        if(StringUtils.isEmpty(asnId) || StringUtils.isEmpty(palletNo)){
            return Result.error("请求参数异常!");
        }
        asnId = CryptoUtil.desEncrypt(asnId, CryptoUtil.KEY, CryptoUtil.IV);
        palletNo = CryptoUtil.desEncrypt(palletNo, CryptoUtil.KEY, CryptoUtil.IV);
        if(!StringUtils.isEmpty(searchParam)){
            searchParam = CryptoUtil.desEncrypt(searchParam, CryptoUtil.KEY, CryptoUtil.IV);
        }
        List<WmsASNReceiveVo> receiveVos = wmsPdaService.findReceiveDetailListByParam(asnId,searchParam);
        String finalPalletNo = palletNo;
        receiveVos.forEach(t->{
            t.setPalletNo(finalPalletNo);
        });
        return Result.OK(receiveVos);
    }

    /**
     * 加载收货明细相关信息
     * */
    @RequestMapping(value = "/initReceiveDetailInputInfo", method = RequestMethod.GET)
    public Result<?> initReceiveDetailInputInfo(@RequestParam(name = "detailId") String detailId) {
        if(StringUtils.isEmpty(detailId)){
            return Result.error("请求参数异常!");
        }
        detailId = CryptoUtil.desEncrypt(detailId, CryptoUtil.KEY, CryptoUtil.IV);
        return wmsPdaService.initReceiveDetailInputInfo(detailId);
    }

    /**
     * PDA收货确认
     * */
    @RequestMapping(value = "/receiveDetail", method = RequestMethod.POST)
    public Result<?> receiveDetail(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
        return wmsPdaService.receiveDetail(jsonObject);
    }




}
